home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7331 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: cscsun3.larc.nasa.gov!hook
  2. From: hook@cscsun3.larc.nasa.gov (Ed Hook)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: HELP: Illegal Pointer Arithmetic
  5. Date: 25 Feb 1996 17:45:15 GMT
  6. Organization: CSC/NASA Langley Research Center
  7. Distribution: world
  8. Message-ID: <4gq77b$bmo@reznor.larc.nasa.gov>
  9. References: <4gj0ug$730@news.one.net> <danpop.825121139@rscernix> <31306a18.309961701@nntp.ix.netcom.com>
  10. Reply-To: hook@cscsun3.larc.nasa.gov
  11. NNTP-Posting-Host: cscsun3.larc.nasa.gov
  12.  
  13. In article <31306a18.309961701@nntp.ix.netcom.com>, miker3@ix.netcom.com (Mike Rubenstein) writes:
  14. |> danpop@mail.cern.ch (Dan Pop) wrote:
  15. |> 
  16. |> > In <4gj0ug$730@news.one.net> Oren Levin <oren@one.net> writes:
  17. |> > 
  18. |> > >        while (! feof (fin))
  19. |> >                 ^^^^^^^^^^^^^^^^^^^^     
  20. |> > Are there any books teaching this idiocy or is it only Pascal-induced
  21. |> > brain damage?  (See the FAQ.)
  22. |> 
  23. |> Not quite that, but Shildt's Annotated ANSI C Standard says
  24. |> 
  25. |>     The following fragment illustrates how files are commonly 
  26. |>     read:
  27. |> 
  28. |>         do {
  29. |>           ch = fgetc(fp);
  30. |>           /* ... */
  31. |>         } while (!feof(fp));
  32. |> 
  33. |> Come on Dan.  You're slipping.  Surely you could have guessed who
  34. |> teaches this idiocy.
  35. |>
  36.    It depresses me to have to defend Schildt, but that loop actually
  37.    works as advertised. (I *do* question his use of "commonly", since
  38.    I have encountered _any_ code that does it that way ... .) Anyhow,
  39.    since 'feof()' is called *after* each iteration of the loopbody,
  40.    the loop terminates precisely after the last character is fetched
  41.    from the file.
  42.  
  43. |> 
  44. |> Michael M Rubenstein
  45.  
  46. -- 
  47.  Ed Hook                              |       Coppula eam, se non posit
  48.  Computer Sciences Corporation        |         acceptera jocularum.
  49.  NASA Langley Research Center         | Me? Speak for my employer?...<*snort*>
  50.  Internet: hook@cscsun3.larc.nasa.gov |        ... Get a _clue_ !!! ...
  51.